package com.learn.english.service.impl;

import com.learn.english.mapper.NoteMapper;
import com.learn.english.model.entity.Note;
import com.learn.english.service.INoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NoteServiceImpl implements INoteService {

    @Autowired
    private NoteMapper noteMapper;

    @Override
    public Note getById(Integer id) {
        return noteMapper.selectById(id);
    }

    @Override
    public List<Note> listByUserId(Integer userId) {
        return noteMapper.selectByUserId(userId);
    }

    @Override
    public List<Note> listAll() {
        return noteMapper.selectAll();
    }

    @Override
    public List<Note> listWithPagination(Integer userId, String title, int offset, int limit) {
        return noteMapper.selectWithPagination(userId, title, offset, limit);
    }

    @Override
    public long count(Integer userId, String title) {
        return noteMapper.count(userId, title);
    }

    @Override
    public void save(Note note) {
        noteMapper.insert(note);
    }

    @Override
    public boolean updateById(Note note) {
        return noteMapper.updateById(note) > 0;
    }

    @Override
    public void removeByIds(List<Integer> ids) {
        if (ids != null && !ids.isEmpty()) {
            noteMapper.deleteByIds(ids);
        }
    }
}